<?php
/* -------------------------------------------------------------------------------------
* 	ID:						$Id: brand.php 502 2014-01-31 15:50:06Z phone.mueller@googlemail.com $
* 	Letzter Stand:			$Revision: 502 $
* 	zuletzt geaendert von:	$Author: siekiera $
* 	Datum:					$Date: 2014-01-31 15:50:06 +0000 (Fri, 31 Jan 2014) $
*
* 	SEO:mercari by Siekiera Media
* 	http://www.seo-mercari.de
*
* 	Copyright (c) since 2011 SEO:mercari
* --------------------------------------------------------------------------------------
* 	based on:
* 	(c) 2000-2001 The Exchange Project  (earlier name of osCommerce)
* 	(c) 2002-2003 osCommerce - www.oscommerce.com
* 	(c) 2003     nextcommerce - www.nextcommerce.org
* 	(c) 2005     xt:Commerce - www.xt-commerce.com
*
* 	Released under the GNU General Public License
* ----------------------------------------------------------------------------------- */

$box_smarty = new Smarty();
$get_brand = '';

if(isset($_GET['brand']))
	$get_brand = $_GET['brand'];
elseif(isset($_GET['filter_id']))
	$get_brand = $_GET['filter_id'];

if (!CacheCheck()) {
	$cache = false;
	$box_smarty->caching = false;

} else {
	$cache = true;
	$box_smarty->caching = true;
	$box_smarty->cache_lifetime = CACHE_LIFETIME;
	$box_smarty->cache_modified_check = CACHE_CHECK;
	$cache_id = 'box_brand_'.(int)$get_brand.'_'.$_SESSION['language'].'_';
}

if(!$box_smarty->isCached(CURRENT_TEMPLATE.'/boxes/box_brand.html', $cache_id) || !$cache) {
	
	$box_smarty->assign('tpl_path', 'templates/'.CURRENT_TEMPLATE.'/');
	$box_smarty->assign('html_tpl_path', CURRENT_TEMPLATE.'/html');
	$box_smarty->assign('language', $_SESSION['language']);

	$brand = $db->db_query("SELECT
								m.brand_id,
								m.brand_name,
								m.brand_image
							FROM
								".TABLE_BRAND." as m,
								".TABLE_PRODUCTS." as p
							WHERE
								m.brand_id = p.brand_id
							GROUP BY
								m.brand_id
							ORDER BY
								m.brand_name");
	if($brand->_numOfRows) {
		if(BRAND_AS_LOGO_LIST == 'true') {			
			while(!$brand->EOF) {
				if(MODULE_SEO_URL_INDEX_STATUS == 'True') {
					$url = 'brand-'.$brand->fields['brand_id'].'/'.get_url_friendly_text($brand->fields['brand_name']).'/';
				} else
					$url = href_link(FILENAME_DEFAULT, 'brand='.$brand->fields['brand_id']);

				$brand_logos[] = array('name' => $brand->fields['brand_name'],
										'link' => $url,
										'image' => is_file(DIR_WS_IMAGES.$brand->fields['brand_image']) ? DIR_WS_IMAGES.$brand->fields['brand_image'] : false,
										'class'	=> ($get_brand == $brand->fields['brand_id']) ? ' class="current_manu"' : false);
				$brand->MoveNext();
			}
			$list_data = get_list_data('brand');
			if($brand->_numOfRows > 1 && $list_data['box_effect'] != 'none')	{
				$get[] = 'bl='.$list_data['box_effect'];
				$get[] = 'bld='.$list_data['effect_direction'];
			}
			$box_smarty->assign('IS_LOGO', true);
			$box_brand = $brand_logos;
			
		} elseif($brand->_numOfRows <= MAX_DISPLAY_BRAND_IN_A_LIST) {
			$brand_list = '';
			while (!$brand->EOF) {
				$brand_name = ((strlen($brand->fields['brand_name']) > MAX_DISPLAY_BRAND_NAME_LEN) ? substr($brand->fields['brand_name'], 0, MAX_DISPLAY_BRAND_NAME_LEN).'..' : $brand->fields['brand_name']);
				if(isset($get_brand) && ($get_brand == $brand->fields['brand_id']))
					$brand_name = '<b>'.$brand_name.'</b>';

				$brand_list .= '<a href="brand-'.$brand->fields['brand_id'].'/'.get_url_friendly_text($brand_name).'/">'.$brand_name.'</a><br />';
				$brand->MoveNext();
			}
			$box_brand = $brand_list;

		} else {
			$dropdown  = '<SELECT name="" onchange="window.location.href=this.value" size="'.MAX_BRANDS_LIST.'" style="width: 100%">';
			if(MODULE_SEO_URL_INDEX_STATUS == 'True')
				$dropdown .= '<option value="'.DIR_WS_CATALOG.'">'.PULL_DOWN_DEFAULT.'</option>';
			else
				$dropdown .= '<option value="'.href_link(FILENAME_DEFAULT).'">'.PULL_DOWN_DEFAULT.'</option>';
			while (!$brand->EOF) {
				$name_raw = ((strlen($brand->fields['brand_name']) > MAX_DISPLAY_BRAND_NAME_LEN) ? substr($brand->fields['brand_name'], 0, MAX_DISPLAY_BRAND_NAME_LEN).'..' : $brand->fields['brand_name']);
				$name_val = get_url_friendly_text($brand->fields['brand_name']);
				if(MODULE_SEO_URL_INDEX_STATUS == 'True')
					$url = 'brand-'.$brand->fields['brand_id'].'/'.$name_val.'/';
				else
					$url = href_link(FILENAME_DEFAULT, 'brand='.$brand->fields['brand_id']);
				$dropdown .= '<option value="'.$url.'"'.($get_brand == $brand->fields['brand_id'] ? ' selected' : '').'>'.$name_raw.'</option>';
			$brand->MoveNext();
			}
			$dropdown .= '</select>';
			if(MODULE_SEO_URL_INDEX_STATUS == 'True')
				$box_brand  = draw_form('brand', DIR_WS_CATALOG, 'GET');
			else
				$box_brand  = draw_form('brand', 'index.php', 'GET');
			$box_brand .= $dropdown;
			$box_brand .= '</form>';
		}
		$box_smarty->assign('BOX_CONTENT', $box_brand);
		if(!$cache)
			$box_content = $box_smarty->fetch(CURRENT_TEMPLATE.'/boxes/box_brand.html');
		else
			$box_content = $box_smarty->fetch(CURRENT_TEMPLATE.'/boxes/box_brand.html', $cache_id);
	}
}